<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
export default {
  props: {
    probeType: {
      type: Number,
      default() {
        return 0;
      },
    },
    pullUpload: {
      type: Boolean,
      default() {
        return false;
      },
    },
  },
  data() {
    return {
      scroll: null,
    };
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      // 被bscroll包围的标签只有button可以点击 像div span等标签必须加上该属性才可点击
      click: true,
      probeType: this.probeType,
      pullUpLoad: this.pullUpload,
    });
    // 监听滚动的位置
    this.scroll.on("scroll", (position) => {
      console.log(position);

      this.$emit("scroll", position);
    });
    // 上拉加载更多
    this.scroll.on("pullingUp", () => {
      this.$emit("pullupload");
      console.log("加载");
    });
  },
  methods: {
    //   控制滚动到那个位置 直接赋值 代表默认值
    scrollTo(x, y, time = 300) {
      this.scroll.scrollTo(x, y, time);
    },
    // 这个方法解决只能上拉一次的问题 加上后可以多次上拉加载
    finishPullup() {
      this.scroll.finishPullUp();
    },
    refresh() {
      this.scroll.refresh();
      // console.log('111');
    },
  },
};
</script>
<style scoped></style>
